package easy;

import util.PrintUtils;

import java.util.*;

public class Solution_1331 {

    public int[] arrayRankTransform(int[] arr) {
        if (arr.length==0) {
            return arr;
        }
        List<Integer> list = new ArrayList<>();
        for (int i : arr) {
            list.add(i);
        }
        Collections.sort(list);
        int sort = 1;
        Map<Integer, Integer> map = new HashMap<>();
        map.put(list.get(0), sort++);
        for (int i = 1; i < list.size(); i++) {
            if (!list.get(i).equals(list.get(i - 1))) {
                map.put(list.get(i), sort++);
            }
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i] = map.get(arr[i]);
        }
        return arr;
    }

    public static void main(String[] args) {
        Solution_1331 model = new Solution_1331();
        PrintUtils.arrayInt(model.arrayRankTransform(new int[]{40, 10, 20, 30}));
        PrintUtils.arrayInt(model.arrayRankTransform(new int[]{100, 100, 100}));
        PrintUtils.arrayInt(model.arrayRankTransform(new int[]{37,12,28,9,100,56,80,5,12}));
    }
}
